package userspace

import (
	"log"

	"eSymCounter/userspace/uprobe"

	"github.com/cilium/ebpf/rlimit"
)

// ebpf的userspace部分

func RunElf(stopper <-chan struct{}) {
	// Allow the current process to lock memory for eBPF resources.
	if err := rlimit.RemoveMemlock(); err != nil {
		log.Fatal(err)
	}

	//注册ebpf程序
	elfstopper := make(chan struct{}, 1)
	go uprobe.InitUprobeElf(elfstopper)

	<-stopper
	elfstopper <- struct{}{}
}

func RunSo(stopper <-chan struct{}) {
	// Allow the current process to lock memory for eBPF resources.
	if err := rlimit.RemoveMemlock(); err != nil {
		log.Fatal(err)
	}

	//注册ebpf程序
	sostopper := make(chan struct{}, 1)
	go uprobe.InitUprobeSo(sostopper)

	<-stopper
	sostopper <- struct{}{}
}
